package View;

import javax.swing.*;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;

public class RobotGrid extends JFrame {

    private static final int GRID_ROWS = 20; // 网格的行数
    private static final int GRID_COLUMNS = 30; // 网格的列数
    private static final int CELL_SIZE = 30; // 每个单元格的尺寸

    public RobotGrid() {
        setTitle("RobotGrid");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(GRID_COLUMNS * CELL_SIZE + 200, GRID_ROWS * CELL_SIZE + 200); // 调整窗口大小
        setLocationRelativeTo(null);

        add(new GridPanel());
    }

    private class GridPanel extends JPanel {
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);

            Graphics2D g2d = (Graphics2D) g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

            // 绘制网格及图标
            for (int row = 0; row < GRID_ROWS; row++) {
                for (int col = 0; col < GRID_COLUMNS; col++) {
                    int x = col * CELL_SIZE + 100;
                    int y = row * CELL_SIZE + 100;
                    // 绘制单元格边框
                    g2d.setColor(Color.LIGHT_GRAY);
                    g2d.drawRect(x, y, CELL_SIZE, CELL_SIZE);
                }
            }
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            RobotGrid frame = new RobotGrid();
            frame.setVisible(true);
        });
    }
}

